﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Pipo.AeExtensions;

namespace Pipo.DialogExtensions
    {
    public partial class DialogDatePeriodFrm:DevExpress.XtraEditors.XtraForm
        {
        private AeReturnvalue _returnvalue;

        public AeReturnvalue Showme(DateTime? defaultfromdate = null,DateTime? defaulttodate = null)
            {
            //_returnvalue = new AeReturnvalue();
            _returnvalue.Cancelled = true;
            dateEdit1.EditValue = defaultfromdate;
            dateEdit2.EditValue = defaulttodate;
            ShowDialog();
            return _returnvalue;
            }


        public DialogDatePeriodFrm()
            {
            InitializeComponent();
           
            }

        private void DialogDatePeriodFrmFormClosing(object sender,FormClosingEventArgs e)
            {
            switch ( this.DialogResult)
                {
                    case DialogResult.None:
                        break;
                    case DialogResult.OK:
                        break;
                    case DialogResult.Cancel:
                        _returnvalue.Cancelled = true;
                        MessageBox.Show(@"CAncelled");
                        break;
                    case DialogResult.Abort:
                        break;
                    case DialogResult.Retry:
                        break;
                    case DialogResult.Ignore:
                        break;
                    case DialogResult.Yes:
                        break;
                    case DialogResult.No:
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

        private void BtnokClick(object sender,EventArgs e)
            {
            try
                {
                if (!(dateEdit1.EditValue != null & dateEdit2.EditValue != null))
                    {
                    AskUser.PopupValidationError("Please check your dates.");
                    return;
                    }
                if (dateEdit1.DateTime.Date > dateEdit2.DateTime.Date)
                    {
                    AskUser.PopupValidationError("Period from must be before Perio To.");
                    return;
                    }
                DialogResult = DialogResult.OK;
                DateTime[] dates = new DateTime[2];
                dates[0] = dateEdit1.DateTime.Date;
                dates[1] = dateEdit2.DateTime.Date;
                _returnvalue.Rowdata = dates;
                _returnvalue.Cancelled = false;
                Close();
                }
            catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }
            }

        private void BtncancelClick(object sender,EventArgs e)
            {
            DialogResult = DialogResult.Cancel;
            Close();
            }
        }
    }